<template>
    <el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
        <el-form-item label="校区" prop="name" required>
            <el-input v-model="formData.name" name="name" clearable/>
        </el-form-item>
        <el-form-item label="过期时间" prop="expiration_time" required>
            <el-date-picker
                v-model="formData.expiration_time"
                type="datetime"
                name="expiration_time"
                placeholder="请选择过期时间"
                value-format="YYYY-MM-DD HH:mm:ss"
                clearable
            />
        </el-form-item>
        <div class="flex justify-end">
            <el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
        </div>
    </el-form>
</template>

<script lang="ts" setup>
import {useCreate} from '@/composables/curd/useCreate'
import {useShow} from '@/composables/curd/useShow'
import {onMounted} from 'vue'

const props = defineProps({
    primary: [String, Number],
    api: String,
})

const {formData, form, loading, submitForm, close} = useCreate(props.api, props.primary)

if (props.primary) {
    useShow(props.api, props.primary, formData)
}

const emit = defineEmits(['close'])
onMounted(() => {
    close(() => emit('close'))
})
</script>
